//package com.zmn.plat.dubbo.impl.product.price;
//
//import java.util.Collections;
//import java.util.List;
//import java.util.stream.Collectors;
//
//import javax.annotation.Resource;
//
//import lombok.extern.slf4j.Slf4j;
//import org.apache.dubbo.config.annotation.Service;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.util.CollectionUtils;
//
//import com.zmn.common.dto2.ResponseDTO;
//import com.zmn.common.utils.number.NumberUtil;
//import com.zmn.manager.common.database.annotation.ReadOnlyConnection;
//import com.zmn.plat.business.interfaces.product.item.ItemBService;
//import com.zmn.plat.common.dictionary.PlatErrorCodeDict;
//import com.zmn.plat.common.dto.product.MaxAveragePriceDRO;
//import com.zmn.plat.common.dto.product.item.ItemDIO;
//import com.zmn.plat.common.dto.product.item.ItemDRO;
//import com.zmn.plat.dubbo.interfaces.product.price.ItemPriceListRemoteService;
//import com.zmn.plat.dubbo.utils.DubboConsts;
//import com.zmn.plat.manager.dictionary.ProductDict;
//
///**
// * @author tanghongjun
// * @version v1.0 @类说明：
// * @since 2020年3月30日18:15:36
// */
//@Service(version = DubboConsts.INTERFACE_VERSION, validation = "true")
//@Slf4j
//public class ItemPriceListRemoteServiceImpl implements ItemPriceListRemoteService {
//
//    private Logger logger = LoggerFactory.getLogger(ItemPriceListRemoteServiceImpl.class);
//
//    private static final String TAG = "服务项价格 dubbo 接口";
//    @Resource
//    private ItemBService itemBService;
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<MaxAveragePriceDRO> getMaxAveragePriceByChannelIdAndTypeAndCityIdAndProductId(Integer channelId, Integer type, Integer cityId, Integer productId) {
//        log.info("getMaxAveragePriceByChannelIdAndTypeAndCityIdAndProductId：channelId={},type={},cityId={},productId={}", channelId, type, cityId, productId);
//
//        if (NumberUtil.isNullOrZero(cityId) || NumberUtil.isNullOrZero(productId)) {
//            return ResponseDTO.fromErrorCodeTable(PlatErrorCodeDict.ERROR_CODE_PANAM_NULL);
//        }
//
//        ItemDIO itemDIO = new ItemDIO();
//        itemDIO.setChannelId(channelId);
//        itemDIO.setCityId(cityId);
//        itemDIO.setBizType(type);
//        itemDIO.setProductId(productId);
//        List<ItemDRO> itemDROS = itemBService.listItemByDIO(itemDIO);
//        List<Integer> priceList = itemDROS.stream().filter(itemDRO -> NumberUtil.isPositiveInteger(itemDRO.getPrice())).map(ItemDRO::getPrice).collect(Collectors.toList());
//        MaxAveragePriceDRO maxAveragePriceDRO = new MaxAveragePriceDRO();
//
//        if (CollectionUtils.isEmpty(priceList)) {
//            // maxAveragePriceDRO.setAverage(ProductDict.ZERO);
//            // maxAveragePriceDRO.setMax(ProductDict.ZERO);
//            // return ResponseDTO.success(maxAveragePriceDRO);
//            return ResponseDTO.fail("服务项不存在");
//        }
//
//        int total = 0;
//        for (int i = 0; i < priceList.size(); i++) {
//            total += priceList.get(i);
//        }
//        total = total / ProductDict.HUNDRED;
//        int price = Math.round(total / itemDROS.size());
//        maxAveragePriceDRO.setMax(Collections.max(priceList));
//        maxAveragePriceDRO.setAverage(price * ProductDict.HUNDRED);
//        return ResponseDTO.success(maxAveragePriceDRO);
//    }
//
//}
